﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class EditRoleControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox jiaosename, jiaosememo, txtID;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            string strid = base.Page.Request["ID"];
            string action = base.Page.Request["action"];
            
            if (!base.Page.IsPostBack) {
                if (string.IsNullOrEmpty(strid)) { txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } else { 
                    txtID.Text = strid;
                    EluZSProvider.Role role = _EluZSDataProvider.GetRole(strid);
                    jiaosename.Text = role.Rolename;
                    jiaosememo.Text = role.Memo;
                }
            }
            if (!string.IsNullOrEmpty(action) && action == "del")
            {
                bool del = _EluZSDataProvider.DeleteXmByID("zs_role", "id", strid);
                if (del) { base.Page.Response.Redirect("role.aspx"); }
            }
            Button savebtn = (Button)FindControl("savebtn");
            savebtn.Click += new EventHandler(savebtn_Click);
        }
        protected void InitControl() {
            jiaosename = (TextBox)FindControl("jiaosename");
            jiaosememo = (TextBox)FindControl("jiaosememo");
            txtID = (TextBox)FindControl("txtID");
        }

        protected void savebtn_Click(object sender, EventArgs e)
        {
            string strid = base.Page.Request["ID"];
            EluZSProvider.Role role = new EluZSProvider.Role();
            role.Id = txtID.Text;
            role.Rolename = jiaosename.Text;
            role.Memo = jiaosememo.Text;
            role.Addtime = (DateTime?)System.DateTime.Now;
            bool save = _EluZSDataProvider.SaveRole(strid, role);
            if (save) { base.Page.Response.Redirect("Role.aspx"); }
        }
        
    }
}


